import {
  Branch, BranchIssuesTickets, Figure,
  IScoreModel, PercentItem, RankedBranch, ScoreContrastItem, ScoreModelAndData, ScoreTrendItem
} from '@/api-scp/types'

const Branches: Branch[] = [
  {
    name: '郑州分行',
    region: '郑州'
  },
  {
    name: '信阳分行',
    region: '信阳'
  },
  {
    name: '周口分行',
    region: '周口'
  },
  {
    name: '平顶山分行',
    region: '平顶山'
  },
  {
    name: '三门峡分行',
    region: '三门峡'
  },
  {
    name: '商丘分行',
    region: '商丘'
  },
  {
    name: '济源分行',
    region: '济源'
  },
  {
    name: '南阳分行',
    region: '南阳'
  },
  {
    name: '开封分行',
    region: '开封'
  },
  {
    name: '洛阳分行',
    region: '洛阳'
  },
  {
    name: '鹤壁分行',
    region: '鹤壁'
  },
  {
    name: '新乡分行',
    region: '新乡'
  },
  {
    name: '安阳分行',
    region: '安阳'
  },
  {
    name: '金水东路支行',
    region: '郑州'
  },
  {
    name: '许昌支行',
    region: '许昌'
  },
  {
    name: '象湖支行',
    region: '象湖'
  },
  {
    name: '驻马店分行',
    region: '驻马店'
  },
  {
    name: '焦作分行',
    region: '焦作'
  },
  {
    name: '濮阳分行',
    region: '濮阳'
  },
  {
    name: '漯河分行',
    region: '漯河'
  }
]

const IssueCounts = [
  34, 44, 54, 64, 74, 84, 94, 104, 114, 124,
  134, 144, 154, 164, 174, 184, 194, 204, 214, 224
]

const RankedBranches: RankedBranch[] = Branches.map(
  (b, i) => {
    const rb = b as RankedBranch
    // rb.rank = i + 1
    rb.value = IssueCounts[i]
    if (i % 4 === 0) {
      rb.rankChange = 0
    } else {
      rb.rankChange = (i % 2) * 2 - 1
    }
    return rb
  })

export const getBranches = (): Promise<Branch[]> => {
  return Promise.resolve(Branches)
}

export const getBranchIssues = (): Promise<RankedBranch[]> => {
  return Promise.resolve(RankedBranches)
}

const figuresGroup1: Figure[] = [
  {
    key: 'cc',
    num: '11.26%',
    unit: null,
    desc: '资本充足率',
    color: 'green'
  },
  {
    key: 'dd',
    num: '5.81%',
    unit: null,
    desc: '杠杆率',
    color: 'green'
  },
  {
    key: 'ee',
    num: '5.77%',
    unit: null,
    desc: '不良贷款率',
    color: 'red'
  },
  {
    key: 'ff',
    num: '137.43%',
    unit: null,
    desc: '拨备覆盖率',
    color: 'red'
  },
  {
    key: 'gg',
    num: '0.49%',
    unit: null,
    desc: '资产利润率',
    color: 'red'
  },
  {
    key: 'hh',
    num: '12000',
    unit: '人',
    desc: '在职员工总数',
    color: null
  }
]

export const getOverviewFigures1 = (): Promise<Figure[]> => {
  return Promise.resolve(figuresGroup1)
}

const branchIssuesTickets: BranchIssuesTickets[] = [
  {
    name: '郑州分行',
    issues: 22,
    regs: 1,
    tickets: 3
  },
  {
    name: '信阳分行',
    issues: 13,
    regs: 4,
    tickets: 7
  },
  {
    name: '周口分行',
    issues: 37,
    regs: 6,
    tickets: 4
  },
  {
    name: '平顶山分行',
    issues: 46,
    regs: 2,
    tickets: 9
  },
  {
    name: '三门峡分行',
    issues: 16,
    regs: 7,
    tickets: 3
  },
  {
    name: '商丘分行',
    issues: 12,
    regs: 2,
    tickets: 4
  },
  {
    name: '济源分行',
    issues: 28,
    regs: 5,
    tickets: 5
  },
  {
    name: '南阳分行',
    issues: 25,
    regs: 8,
    tickets: 2
  },
  {
    name: '开封分行',
    issues: 41,
    regs: 2,
    tickets: 6
  },
  {
    name: '洛阳分行',
    issues: 31,
    regs: 1,
    tickets: 3
  },
  {
    name: '鹤壁分行',
    issues: 33,
    regs: 5,
    tickets: 3
  },
  {
    name: '新乡分行',
    issues: 26,
    regs: 7,
    tickets: 5
  },
  {
    name: '安阳分行',
    issues: 17,
    regs: 1,
    tickets: 6
  },
  {
    name: '金水东路支行',
    issues: 13,
    regs: 6,
    tickets: 2
  },
  {
    name: '许昌支行',
    issues: 10,
    regs: 3,
    tickets: 8
  },
  {
    name: '象湖支行',
    issues: 21,
    regs: 6,
    tickets: 1
  },
  {
    name: '驻马店分行',
    issues: 31,
    regs: 2,
    tickets: 9
  },
  {
    name: '焦作分行',
    issues: 41,
    regs: 5,
    tickets: 2
  },
  {
    name: '濮阳分行',
    issues: 31,
    regs: 8,
    tickets: 3
  },
  {
    name: '漯河分行',
    issues: 26,
    regs: 9,
    tickets: 5
  }
]

export const getBranchIssuesTickets = (): Promise<BranchIssuesTickets[]> => {
  return Promise.resolve(branchIssuesTickets)
}

export const ScoreModelMB: IScoreModel = {
  name: '管理基础评分',
  items: [
    {
      field: 'ry',
      name: '合规管理人员情况（15分）',
      max: 15
    },
    {
      field: 'rcsa',
      name: 'RCSA工作开展情况（30分）',
      max: 30
    },
    {
      field: 'kri',
      name: 'KRI工作开展情况（15分）',
      max: 15
    },
    {
      field: 'nb',
      name: '内部检查工作开展情况（30分）',
      max: 30
    },
    {
      field: 'zd',
      name: '合规管理制度情况（10分）',
      max: 10
    }
  ]
}

export const ScoresMBEmpty: ScoreModelAndData = {
  model: ScoreModelMB,
  data: [
    {
      name: '本期得分率',
      seriesDataObj: {}
    },
    {
      name: '上期得分率',
      seriesDataObj: {}
    }
  ]
}

export const getScoresMB = (): Promise<ScoreModelAndData> => {
  return Promise.resolve({
    model: ScoreModelMB,
    data: [
      {
        name: '本期得分率',
        seriesDataObj: {
          ry: 14,
          zd: 8,
          nb: 25,
          kri: 12,
          rcsa: 27
        }
      },
      {
        name: '上期得分率',
        seriesDataObj: {
          ry: 12,
          zd: 10,
          nb: 26,
          kri: 10,
          rcsa: 23
        }
      }
    ]
  })
}

export const getScoresMBForBranchTerm = (branch: string, term: string): Promise<any> => {
  if (term === 'THIS') {
    return Promise.resolve({
      ry: 14,
      zd: 8,
      nb: 25,
      kri: 12,
      rcsa: 27
    })
  } else { // LAST
    return Promise.resolve({
      ry: 12,
      zd: 10,
      nb: 26,
      kri: 10,
      rcsa: 23
    })
  }
}

export const ScoreModelMR: IScoreModel = {
  name: '管理结果评分',
  items: [
    {
      field: 'ldc',
      name: 'LDC收集结果（10分）',
      max: 10
    },
    {
      field: 'cf',
      name: '监管处罚（10分）',
      max: 10
    },
    {
      field: 'nb',
      name: '内部检查结果（10分）',
      max: 10
    },
    {
      field: 'wt',
      name: '问题情况（20分）',
      max: 20
    },
    {
      field: 'yg',
      name: '员工违规情况（20分）',
      max: 20
    },
    {
      field: 'fcx',
      name: '合规非现场检测情况（15分）',
      max: 15
    },
    {
      field: 'kri',
      name: 'KRI工作开展情况（5分）',
      max: 5
    },
    {
      field: 'rcsa',
      name: 'RCSA工作开展情况（10分）',
      max: 10
    }
  ]
}

export const ScoresMREmpty: ScoreModelAndData = {
  model: ScoreModelMR,
  data: [
    {
      name: '本期得分率',
      seriesDataObj: {}
    },
    {
      name: '上期得分率',
      seriesDataObj: {}
    }
  ]
}

export const getScoresMR = (): Promise<ScoreModelAndData> => {
  return Promise.resolve({
    model: ScoreModelMR,
    data: [
      {
        name: '本期得分率',
        seriesDataObj: {
          ldc: 9,
          cf: 8,
          nb: 9,
          wt: 12,
          yg: 15,
          fcx: 15,
          kri: 3,
          rcsa: 9
        }
      },
      {
        name: '上期得分率',
        seriesDataObj: {
          ldc: 6,
          cf: 9,
          nb: 10,
          wt: 15,
          yg: 12,
          fcx: 14,
          kri: 4,
          rcsa: 7
        }
      }
    ]
  })
}

export const getScoreContrast1 = (): Promise<ScoreContrastItem[]> => {
  return Promise.resolve([{
    name: '本机构主动发起的RCSA评估的二级流程数量（15分）',
    thisTerm: 100,
    lastTerm: 90
  }, {
    name: '检查项目对风险点的覆盖率（单一年度）（10分）',
    thisTerm: 96,
    lastTerm: 90
  }, {
    name: '合规管理人员配比（15分）',
    thisTerm: 86,
    lastTerm: 71
  }, {
    name: '本机构检测的KRI数量（15分）',
    thisTerm: 84,
    lastTerm: 67
  }, {
    name: '检查项目对控制点的覆盖率（单一年度）（10分）',
    thisTerm: 55,
    lastTerm: 40
  }
  ])
}

export const getScoreContrast2 = (): Promise<ScoreContrastItem[]> => {
  return Promise.resolve([{
    name: '查询查证不及时的疑点数量（5分）',
    thisTerm: 100,
    lastTerm: 90
  }, {
    name: '由本机构进行查询查证的疑点数量（5分）',
    thisTerm: 96,
    lastTerm: 90
  }, {
    name: '本机构RCSA评估发现的高剩余风险点占比（5分）',
    thisTerm: 86,
    lastTerm: 71
  }, {
    name: '本机构RCSA评估发现的失效控制点占比（5分）',
    thisTerm: 84,
    lastTerm: 67
  }, {
    name: '监管处罚金额（5分）',
    thisTerm: 55,
    lastTerm: 40
  }
  ])
}

export const getScorePercentage1 = (): Promise<PercentItem[]> => {
  return Promise.resolve([
    {
      name: '检查项目对控制点的\n覆盖率（单一年度）',
      percent: 53.6
    }, {
      name: '分行层面\n规章制度数量',
      percent: 60
    }, {
      name: '本机构RCSA评估涉及的\n二级流程数量',
      percent: 66.9
    }, {
      name: '本机构检测的\nKRI数量',
      percent: 82
    }, {
      name: '合规管理\n人员配比',
      percent: 84
    }
  ])
}

export const getScoreTrendData = (): Promise<ScoreTrendItem[]> => {
  return Promise.resolve([
    {
      term: 'n-4',
      termName: 'N-4期',
      overall: 5410,
      mbDim: 92.5,
      mrDim: 63.7
    },
    {
      term: 'n-3',
      termName: 'N-3期',
      overall: 5481,
      mbDim: 88.1,
      mrDim: 67.8
    },
    {
      term: 'n-2',
      termName: 'N-2期',
      overall: 5800,
      mbDim: 82.9,
      mrDim: 75.3
    },
    {
      term: 'n-1',
      termName: 'N-1期',
      overall: 5040,
      mbDim: 78.1,
      mrDim: 70.3
    },
    {
      term: 'n',
      termName: '当期',
      overall: 6386,
      mbDim: 88.2,
      mrDim: 78.5
    }
  ])
}
